package com.ruoyi.ihome.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ihome.domain.TagAndHome;
import com.ruoyi.ihome.service.ITagAndHomeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 标签房间中间表Controller
 * 
 * @author NING
 * @date 2024-08-12
 */
@RestController
@RequestMapping("/ihome/Taghome")
public class TagAndHomeController extends BaseController
{
    @Autowired
    private ITagAndHomeService tagAndHomeService;

    /**
     * 查询标签房间中间表列表
     */
    @PreAuthorize("@ss.hasPermi('ihome:home:list')")
    @GetMapping("/list")
    public TableDataInfo list(TagAndHome tagAndHome)
    {
        startPage();
        List<TagAndHome> list = tagAndHomeService.selectTagAndHomeList(tagAndHome);
        return getDataTable(list);
    }

    /**
     * 导出标签房间中间表列表
     */
    @PreAuthorize("@ss.hasPermi('ihome:home:export')")
    @Log(title = "标签房间中间表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TagAndHome tagAndHome)
    {
        List<TagAndHome> list = tagAndHomeService.selectTagAndHomeList(tagAndHome);
        ExcelUtil<TagAndHome> util = new ExcelUtil<TagAndHome>(TagAndHome.class);
        util.exportExcel(response, list, "标签房间中间表数据");
    }

    /**
     * 获取标签房间中间表详细信息
     */
    @PreAuthorize("@ss.hasPermi('ihome:home:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tagAndHomeService.selectTagAndHomeById(id));
    }

    /**
     * 新增标签房间中间表
     */
    @PreAuthorize("@ss.hasPermi('ihome:home:add')")
    @Log(title = "标签房间中间表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TagAndHome tagAndHome)
    {
        return toAjax(tagAndHomeService.insertTagAndHome(tagAndHome));
    }

    /**
     * 修改标签房间中间表
     */
    @PreAuthorize("@ss.hasPermi('ihome:home:edit')")
    @Log(title = "标签房间中间表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TagAndHome tagAndHome)
    {
        return toAjax(tagAndHomeService.updateTagAndHome(tagAndHome));
    }

    /**
     * 删除标签房间中间表
     */
    @PreAuthorize("@ss.hasPermi('ihome:home:remove')")
    @Log(title = "标签房间中间表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tagAndHomeService.deleteTagAndHomeByIds(ids));
    }
}
